﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;


public partial class temaiyao : System.Web.UI.Page
{
    private static string sqlconn = System.Configuration.ConfigurationManager.AppSettings["sqlcon"].ToString().Trim();
  
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gvyaopin.Visible = false;
            gvhu.Visible = false;

          
           
        }
       
    }
     protected void Binddate()
    {
        users us = new users();
        gvyaopin.DataSource = us.GetAllxiaoshou(us);
        gvyaopin.DataBind();
    }
    /*protected void Binddat()
    {
        users us = new users();
        us.name = Label2.Text.ToString().Trim();
        gvhu.DataSource = us.Getonehu(us);
        gvhu.DataBind();
    }*/
    protected void btncha_Click(object sender, EventArgs e)
    {

        string name = txtname.Text.Trim();
        SqlConnection coon = new SqlConnection(sqlconn);
        try
        {
            coon.Open();

            if (DropDownList1.SelectedIndex == 0)
            {
                string sq = "select * from Y_TABLE where Y_NAME='" + name + "'";
                SqlCommand codd = new SqlCommand(sq, coon);
                SqlDataReader rd = codd.ExecuteReader();
                if (rd.Read())
                {
                    coon.Close();
                    coon.Open();

                    SqlDataAdapter adp = new SqlDataAdapter(sq, coon);
                    try
                    {
                        DataSet ds = new DataSet();
                        adp.Fill(ds, "Y_TABLE");

                        gvyaopin.DataSource = ds.Tables[0].DefaultView;
                        gvyaopin.DataBind();
                        gvyaopin.Visible = true;
                    }
                    catch (SqlException ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        coon.Close();
                    }
                }
                else
                {
                    Response.Write("<script>window.alert(\"未查询到符合的信息！\")</script>");
                }
            }
            else
            {







                           users us = new users();
                           
                           us.name = name;
                          
                               int result = us.chayonghu(us);
                               if (result != 0)
                               {
                                   //SqlDataReader rd = us.getallyonghu(us);
                                  // while (rd.Read())
                                   //{
                                       if (txtname .Text  == Session["name"].ToString ().Trim ())
                                       {

                                           gvhu.DataSource = us.Getonehu(us);
                                           gvhu.DataBind();
                                           gvhu.Visible = true;
                                       }
                                       else
                                       {
                                           Response.Write("<script>window.alert(\"您只能查询本人的个人信息！\")</script>");
                                       }
                                   //}
                               }
                               else
                               {
                                   Response.Write("<script>window.alert(\"未查询到符合的信息！\")</script>");
                               }
                           
                           
                      
                        
                  
               
              
                
               /* string sql = "select * from H_TABLE where  H_NAME='" + name + "'";

                SqlCommand comm = new SqlCommand(sql, coon);


                SqlDataReader rs = comm.ExecuteReader();
                
               if (rs.Read())
                {
                    coon.Close();
                    coon.Open();

                    SqlDataAdapter adp = new SqlDataAdapter(sql, coon);
                   
                          try
                        {
                       
                                 DataSet ds = new DataSet();
                                 adp.Fill(ds, "H_TABLE");
                            
                                  gvhu.DataSource = ds.Tables[0].DefaultView;
                                  gvhu.DataBind();
                                  gvhu.Visible = true;
                             

                             

                         }
                         catch (SqlException ex)
                         {
                             throw new Exception(ex.Message);
                         }
                         finally
                         {
                             coon.Close();
                         }
                    }
                      
                  
                     else
                     {
                         Response.Write("<script>window.alert(\"未查询到符合的信息！\")</script>");
                     }
                        
                    
                
                
                */

            }
        }
        catch (SqlException ex)
        { throw new Exception(ex.Message); }
        finally
        {
            coon.Close();
        }



      
    }
}